#define DelphesData_cxx
#include "DelphesData.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <iostream>
#include "Jet.h"
#include "Muon.h"
#include "Electron.h"
void DelphesData::SwitchBranches(){
	
	
	fChain->SetBranchStatus("*",0);
	
	
	fChain->SetBranchStatus("Jet_size",1);
	fChain->SetBranchStatus("Jet.Px",1);
	fChain->SetBranchStatus("Jet.Py",1);
	fChain->SetBranchStatus("Jet.Pz",1);
	fChain->SetBranchStatus("Jet.E",1);
	
	
	fChain->SetBranchStatus("Electron_size",1);
	fChain->SetBranchStatus("Electron.Px",1);
	fChain->SetBranchStatus("Electron.Py",1);
	fChain->SetBranchStatus("Electron.Pz",1);
	fChain->SetBranchStatus("Electron.E",1);
	fChain->SetBranchStatus("Electron.Charge",1);
	
	fChain->SetBranchStatus("Muon_size",1);
	fChain->SetBranchStatus("Muon.Px",1);
	fChain->SetBranchStatus("Muon.Py",1);
	fChain->SetBranchStatus("Muon.Pz",1);
	fChain->SetBranchStatus("Muon.E",1);
	fChain->SetBranchStatus("Muon.Charge",1);
	
	
	};

void DelphesData::FillEvtData(unsigned int ientry){
  if (!fChain){
	  std::cerr<<"Tree Not Initialized ... FAILURE"<<std::endl;
	  exit (8);
	  }
//std::cout<<"oltaaaaaaaaaaaaaaaaaaaaaaaaaa 1 " <<std::endl;
fChain->GetEntry(ientry);
//std::cout<<"oltaaaaaaaaaaaaaaaaaaaaaaaaaa 2 " <<std::endl;
  //std::cout<<"Electron container size: "<<Electron_size<<std::endl;
  //Fill MET


  MET=ETmis_ET[1]; 
  Ntrks=Tracks_size;
  //initialize a dummy Lorentz vector to set particle 4 momenta
  TLorentzVector lv(0,0,0,0);
//std::cout<<"oltaaaaaaaaaaaaaaaaaaaaaaaaaa 3 " <<std::endl;  
//Fill electrons
  
  for(int i=0;i<Jet_size;i++){
    lv.SetPxPyPzE(double(Jet_Px[i]),double(Jet_Py[i]),double(Jet_Pz[i]),double(Jet_E[i]));
    Jet theJet;
    theJet.setP4(lv);
    theJet.setEmFrac(Jet_EHoverEE[i]);
    jets->push_back(theJet);
//std::cout<<"oltaaaaaaaaaaaaaaaaaaaaaaaaaa 4 " <<std::endl;
    
  }


  for (int i=0;i<Electron_size;i++){//fill electrons-positrons
   
    lv.SetPxPyPzE(Electron_Px[i],Electron_Py[i],Electron_Pz[i],Electron_E[i]);
    Electron theLepton;
    theLepton.setP4(lv);
    //set lepton charge here
    theLepton.SetCharge(Electron_Charge[i]);
    electrons->push_back(theLepton); 
  }

  
  for (int i=0;i<Muon_size;i++){
    lv.SetPxPyPzE(Muon_Px[i],Muon_Py[i],Muon_Pz[i],Muon_E[i]);
    Muon theMuon;
    theMuon.setP4(lv);
    theMuon.SetCharge(Muon_Charge[i]);
    muons->push_back(theMuon);
    
  }
  
  //if (ientry%1000 ==0)std::cout<<(double(ientry)/99999.)*100<<" %"<<'\r'<<std::flush;
  
}
